package com.okilo.online.app.common

import com.okilo.online.app.OkiloApplication
import com.okilo.online.app.base.OkiloBasePet
import com.okilo.online.app.request.IHttpCallback
import com.okilo.online.app.tools.extensions.getStringRes
import org.json.JSONObject

/**
 * CommonPresenter
 * @Author wwdeng
 * @CreateTime: 2024/11/20 10:32
 * @Annotation：
 */
abstract class OkiloComPet(private val iView: IOkiloComView?): OkiloBasePet() {

    /**
     * 接口请求
     */
    fun doPostAction(httpUrl: String, params: JSONObject, callback: IHttpCallback){
        iView?.getAct()?.doPostAction(httpUrl, params,object : IHttpCallback{
            override fun onRequestSuccess(data: JSONObject) {
                callback.onRequestSuccess(data)
            }

            override fun onRequestError(error: JSONObject) {
                callback.onRequestError(error)
            }

            override fun onRequestFinish() {
                callback.onRequestFinish()
            }
        })
    }

    /**
     * 添加埋点
     */
    fun addEventPointRequestAction(eventName: String, eventRemark: String = "") {
        iView?.getAct()?.addEventPointRequestAction(eventName,eventRemark)
    }

    /**
     * getString
     */
    fun getString(strId: Int): String?{
        if (iView?.getContext() == null){
            return OkiloApplication.app.getStringRes(strId)
        }
        return iView.getContext()?.getStringRes(strId)
    }
}